package cn.lyw.discount.controller.controller;

import cn.common.beancopy.util.BeanCopierUtil;
import cn.common.restresult.util.RestResult;
import cn.lyw.discount.controller.dto.AddAdminDiscountDTO;
import cn.lyw.discount.controller.dto.DelAdminDiscountDTO;
import cn.lyw.discount.controller.dto.EditAdminDiscountDTO;
import cn.lyw.discount.controller.dto.GetAdminDiscountByStateDTO;
import cn.lyw.discount.controller.vo.GetAdminDiscountAllVO;
import cn.lyw.discount.controller.vo.GetAdminDiscountByIdVO;
import cn.lyw.discount.controller.vo.GetAdminDiscountByStateVO;
import cn.lyw.discount.service.bo.AddAdminDiscountBO;
import cn.lyw.discount.service.bo.DelAdminDiscountBO;
import cn.lyw.discount.service.bo.EditAdminDiscountBO;
import cn.lyw.discount.service.bo.GetAdminDiscountByStateBO;
import cn.lyw.discount.service.domain.GetAdminDiscountAllDO;
import cn.lyw.discount.service.domain.GetAdminDiscountByIdDO;
import cn.lyw.discount.service.domain.GetAdminDiscountByStateDO;
import cn.lyw.discount.service.service.AdminDiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @Author lyw
 * @Description 后台优惠券
 * @Date 10:45 2021/7/20
 * @Param
 * @return
 */
@RestController
@RequestMapping("/adminDiscount")
public class AdminDiscountController {

    @Autowired
    private AdminDiscountService adminDiscountService;


    /**
     * @return
     * @Author lyw
     * @Description 查询全部优惠券信息
     * @Date 9:40 2021/7/21
     * @Param
     */
    @PostMapping("/getAdminDiscountAll")
    public RestResult<List<GetAdminDiscountAllVO>> getAdminDiscountAll() {
        //调用service方法
        RestResult<List<GetAdminDiscountAllDO>> adminDiscountAll = adminDiscountService.getAdminDiscountAll();
        //转换返回值
        List<GetAdminDiscountAllVO> getAdminDiscountAllVOS = BeanCopierUtil.copyList(adminDiscountAll.getData(), GetAdminDiscountAllVO.class);

        return new RestResult<>(getAdminDiscountAllVOS);
    }


    /**
     * @return
     * @Author lyw
     * @Description 根据状态查询优惠券
     * @Date 9:51 2021/7/21
     * @Param
     */
    @PostMapping("/getAdminDiscountByState")
    public RestResult<List<GetAdminDiscountByStateVO>> getAdminDiscountByState(GetAdminDiscountByStateDTO dto) {
        //转换参数
        GetAdminDiscountByStateBO getAdminDiscountByStateBO = BeanCopierUtil.copyObj(dto, GetAdminDiscountByStateBO.class);
        //调用service方法
        RestResult<List<GetAdminDiscountByStateDO>> adminDiscountByState = adminDiscountService.getAdminDiscountByState(getAdminDiscountByStateBO);
        //转换返回值
        List<GetAdminDiscountByStateVO> getAdminDiscountByStateVOS = BeanCopierUtil.copyList(adminDiscountByState.getData(), GetAdminDiscountByStateVO.class);

        return new RestResult<>(getAdminDiscountByStateVOS);
    }


    /**
     * @return
     * @Author lyw
     * @Description 根据id查询优惠券
     * @Date 9:52 2021/7/21
     * @Param
     */
    @PostMapping("/getAdminDiscountById")
    public RestResult<GetAdminDiscountByIdVO> getAdminDiscountById(String discountId) {
        //调用service方法
        RestResult<GetAdminDiscountByIdDO> adminDiscountById = adminDiscountService.getAdminDiscountById(discountId);
        //转换类型
        GetAdminDiscountByIdVO getAdminDiscountByIdVO = BeanCopierUtil.copyObj(adminDiscountById.getData(), GetAdminDiscountByIdVO.class);

        return new RestResult<>(getAdminDiscountByIdVO);
    }


    /**
     * @return
     * @Author lyw
     * @Description 修改优惠券
     * @Date 10:16 2021/7/21
     * @Param
     */
    @PostMapping("/editAdminDiscount")
    public RestResult editAdminDiscount(EditAdminDiscountDTO dto) {
        //转换参数
        EditAdminDiscountBO editAdminDiscountBO = BeanCopierUtil.copyObj(dto, EditAdminDiscountBO.class);
        //调用service方法
        return adminDiscountService.editAdminDiscount(editAdminDiscountBO);
    }


    /**
     * @return
     * @Author lyw
     * @Description 添加优惠券
     * @Date 10:18 2021/7/21
     * @Param
     */
    @PostMapping("/addAdminDiscount")
    public RestResult addAdminDiscount(AddAdminDiscountDTO dto) {
        //转换参数
        AddAdminDiscountBO addAdminDiscountBO = BeanCopierUtil.copyObj(dto, AddAdminDiscountBO.class);
        //调用service方法
        return adminDiscountService.addAdminDiscount(addAdminDiscountBO);
    }


    /**
     * @return
     * @Author lyw
     * @Description 删除优惠券
     * @Date 10:22 2021/7/21
     * @Param
     */
    @PostMapping("/delAdminDiscount")
    public RestResult delAdminDiscount(DelAdminDiscountDTO dto) {
        //转换参数
        DelAdminDiscountBO delAdminDiscountBO = BeanCopierUtil.copyObj(dto, DelAdminDiscountBO.class);
        //调用service方法
        return adminDiscountService.delAdminDiscount(delAdminDiscountBO);
    }


}
